const SpiderBaseClass = require('./SpiderBaseClass');

const listSize = 20;//列表页面有多少个主播信息
class SpiderChuShou extends SpiderBaseClass {

  /**
   * 获取第一页列表
   */
  static firstListPage() {
    return undefined;
  }

  /**
   * 获取其它页码的列表页面
   * @param page
   */
  static async getListPage(page) {
    const res = await SpiderChuShou.get(SpiderChuShou.listPageUrl(page),
      {dataType: 'json'});

    const list = res.data.data.items.map(room => {
      const meta = room.meta;
      let gender = 0;
      if (meta.gender === 'male')
        gender = 1;
      else if (meta.gender === 'female')
        gender = 2;
      return {
        anchor: {
          room: meta.roomId,
          name: meta.creator,
          gender,
          avatar: meta.avatar,
        },
        type: meta.displayTag,
        data: {
          num_watch: SpiderChuShou.toNumber(meta.onlineCount),
          num_live: 0,
          num_gift: 0,
          num_follower: SpiderChuShou.toNumber(meta.subscriberCount),
        },
      };
    });
    return {
      nextPage: res.data.data.breakpoint,
      hasNextPage: list.length === listSize,
      list,
      page,
    };
  }

  /**
   * 获取直播间信息
   * @param room
   */
  static getRoom(room) {
  }

  /**
   * 生成列表页面的网址
   * @param page
   * @return string
   */
  static listPageUrl(page) {
    return 'https://chushou.tv/live/down-v2.htm' +
      (page ? '?breakpoint=' + page : '');
  }

  /**
   * 生成直播间信息的网址
   * @param id
   * @return string
   */
  roomUrl(id) {
  }

}

module.exports = SpiderChuShou;